<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
class Hotel_mdl extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();
	}
	public	function getSliderLines($cateid=0)	//获取首页幻灯片线路,及图片
	{
			$datawhere=" and model=9 ";
		//	if($cateid){$datawhere.=" and (INSTR(line_class,'-$cateid,') or INSTR(line_class,',$cateid-'))";}
			$sql="select  content,name,folder,type  from dili_u_m_hotel as h inner join dili_attachments as a on a.content=h.id where transparency=1 $datawhere  group by content limit 5 ";
			$SliderLines=$this->db->query($sql)->result();
			return $SliderLines;	
	}	
	public function getHotelInfoByType($p_type = 'hotel_top')
	{
		$arrRet  = array();
		$strSql  = 'select id from dili_u_m_hotel where '.$p_type.' = 1 group by id limit 6';
		$arrId   = $this->db->query($strSql)->result_array();
		foreach ($arrId as $index => $arr)
		{
			$arrInfo = $this->getHotelInfoById($arr['id']);
			$arrRet[$arr['id']] = $arrInfo;
		}
		
		return $arrRet;
	}
	
	public function getHotelInfoById($p_id = 1) 
	{
		$arrRet  = array();
		$strSql1 = 'select id, hotel_name,hotel_desc,hotel_price,hotel_tel,hotel_star,hotel_pos,hotel_addr,hotel_room_num,hotel_info_other,hotel_info_base from dili_u_m_hotel where id = '.$p_id;
		$arr1    = $this->db->query($strSql1)->result_array();
		
		$strSql2 = 'select name,folder,type from dili_attachments where content = '.$p_id;
		$arr2    = $this->db->query($strSql2)->result_array();
		
		$arrRet = $arr1[0] + $arr2[0];
		
		return $arrRet;

	}
	
	public function searchHotel($dllCity = 0,$dllRMB = 0,$txthName = "",$type = 0,$begin_record = 0,$per_page = 10)
	{
		$datawhere = '';

 		if ($dllCity != 0)
 		{
			$datawhere .=" and hotel_city = ',$dllCity,'";
 		}
		// if ($ddlhArea != 0)
 		// {
	 		// $datawhere .='and hotel_pos = '."'".$ddlhArea."'";
 		// }
		
		if ($dllRMB != 0) 
		{
			$datawhere .=' and hotel_price = '."'".$dllRMB."'";
		}
		// if ($ddlStar != 0) 
		// {
			// $datawhere .='and hotel_star = '."'".$ddlStar."'";
		// }
		if ($txthName != '') 
		{
			$datawhere .=' and hotel_name = '."'".$txthName."'";
		}
		
		//$datawhere=" and  hotel_city = $dllCity and hotel_pos = $ddlhArea and hotel_star = $ddlStar";
		if($type==0)
		{
			$sear_fields="count(id) as icount" ;
			$sql = "select ".$sear_fields." from  dili_u_m_hotel where 1=1 $datawhere ";
		//	echo $sql;
		}
		else
		{
			if(!$begin_record)
			{
				$begin_record = 0;
			}
			$sear_fields="h.*,name,folder,type" ;
			$sql="select ".$sear_fields." from  dili_u_m_hotel as h left join dili_attachments as a on h.id=a.content where 1=1 $datawhere group by id limit $begin_record,$per_page";	
		}
		
		$searchHotel=$this->db->query($sql)->result_array();

		return $searchHotel;
				
	}			
}
